<template>
  <ele-page>
    <!-- 搜索表单 -->
    <search @search="reload" v-if="props.action == 'list'" />
    <ele-card :body-style="{ paddingTop: '8px' }">
      <!-- 表格 -->
      <ele-pro-table
        ref="tableRef"
        :columns="columns"
        :datasource="datasource"
        :show-overflow-tooltip="true"
        highlight-current-row
        stripe
        border
        :where="defaultWhere"
      >
        <template #img="{ row }">
          <span
            v-if="row.images !== ''"
            class="pointer blue"
            @click="openImages(row)"
            >查看</span
          >
          <span v-else>无</span>
        </template>
        <template #action="{ row }">
          <el-button-group>
            <el-button type="primary" size="small" @click="openPay(row)">
              付款
            </el-button>

            <!-- <el-button type="danger" size="small" @click="opewBack(row)">
              退回
            </el-button> -->
          </el-button-group>
        </template>
      </ele-pro-table>
    </ele-card>
    <!-- 图片 -->
    <images v-model="showImages" :data="current" />
    <!-- 待付款列表 -->
    <pay v-model="showPay" :data="current" @done="done" />
    <!-- 退回 -->
    <!-- <back v-model="showBack" :data="current" @done="done" /> -->
  </ele-page>
</template>

<script setup>
  import { ref, computed } from 'vue';
  import { pageInsuranceWatingPay } from '@/api/company';
  import Images from './components/trade-pay-images.vue';
  import Search from '@/views/insurance/components/search.vue';
  import Pay from './components/pay.vue';
  // import Back from './components/back.vue';
  const props = defineProps({
    /** 弹窗是否打开 */
    vehicleId: {
      type: Number,
      default: 0
    },
    action: {
      type: String,
      default: 'list'
    }
  });

  /** 表格实例 */
  const tableRef = ref(null);

  /** 表格列配置 */
  const columns = computed(() => {
    const cols = [];

    cols.push(
      {
        width: 70,
        prop: 'id',
        label: '编号'
      },
      {
        label: '车辆信息',
        align: 'center',
        children: [
          {
            width: 60,
            prop: 'area',
            label: '区域'
          },
          {
            width: 120,
            prop: 'plate_number',
            label: '车牌号码'
          },
          {
            prop: 'company',
            label: '车队'
          }
        ]
      },
      {
        label: '付款信息',
        align: 'center',
        children: [
          {
            width: 100,
            prop: 'cate',
            label: '类型'
          },
          {
            width: 180,
            prop: 'insurance',
            label: '保险公司'
          },
          {
            width: 120,
            prop: 'insurance_salesman',
            label: '业务员'
          },
          {
            width: 100,
            prop: 'totalPrice',
            label: '价格'
          },
          {
            width: 110,
            slot: 'img',
            label: '车主付款图片',
            align: 'center'
          }
        ]
      },
      {
        width: 100,
        slot: 'action',
        label: '操作',
        align: 'center',
        fixed: 'right'
      }
    );

    return cols;
  });

  const defaultWhere = {
    vehicle_id: props.vehicleId
  };

  /** 表格数据源 */
  const datasource = async ({ page, limit, where, orders }) => {
    const result = await pageInsuranceWatingPay({
      ...where,
      ...orders,
      page,
      limit
    });
    return result;
  };
  /** 搜索 */
  const reload = (where) => {
    tableRef.value?.reload?.({ page: 1, where });
  };

  const current = ref([]);

  /** 查看图片 */
  const showImages = ref(false);
  const openImages = (data) => {
    current.value = data;
    showImages.value = true;
  };

  /** 退回 */
  const showBack = ref(false);
  const opewBack = (row) => {
    current.value = row;
    showBack.value = true;
  };

  /** 付款 */
  const showPay = ref(false);
  const openPay = (row) => {
    current.value = row;
    showPay.value = true;
  };

  const done = () => {
    showPay.value = false;
    reload();
  };
</script>
